package com.higgins.lawapp.client.settings.handlers;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.higgins.lawapp.client.settings.model.DataSourceModel;


public class ElementListHandler implements ChangeHandler {
//	private final ResearchServiceAsync researchService = GWT.create(ResearchService.class);	
	private Label errorLabel;
	private ListBox listbox;
	private DataSourceModel dataSourceModel;
	
	public ElementListHandler(ListBox listbox, Label errorLabel, DataSourceModel dataSourceModel)	{
		this.listbox = listbox;
		this.errorLabel = errorLabel;
		this.dataSourceModel = dataSourceModel;
	}
	
/*
	private void receiveNameFromServer() {
		researchService.getResearch( 
				new AsyncCallback<Data>() {
					public void onFailure(Throwable caught) {
						errorLabel.setText("Failure to Retrieve Name From Server!!");
					}

					public void onSuccess(Data data) {
						errorLabel.setText(data.getText() + "\n" + data.getUser() + "\n" + data.getAge().toString());
					}
				});
	}
	
	private void sendNameToServer(String text) {
		Data myData = new Data();
		myData.setText(text);
		myData.setUser("Patrick Higgins");
		myData.setAge(new Double(33.0));
		researchService.setResearch(myData, 
				new AsyncCallback<String>() {
					public void onFailure(Throwable caught) {
						errorLabel.setText("Failure to Send Name to Server!!");
					}

					public void onSuccess(String result) {
						errorLabel.setText(result.toString());
					}
				});
	}		*/

	@Override
	public void onChange(ChangeEvent event) {
		// TODO Auto-generated method stub
		dataSourceModel.setElementListItem(listbox.getItemText(listbox.getSelectedIndex()));
	}
	
}